<form method="post" id="frm" name="form">
<table width="735" height="70" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC" bordercolordark="#FFFFFF">
	  <tr>
      	<td style="border-top:1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left:1px solid #CCCCCC"><div align="left" style="color:#0B55C4; font-family:Tahoma; font-size: 16px; font-weight:bold; padding-left:20px">DANH SÁCH KHÁCH HÀNG THÂN THIẾT</div></td>
      	<td style="border-top:1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; height:65px; width:55px">
		<input type="button" value='' onClick="document.form.action='/sitemanager/?m=khtt&b=khtt-insert'; document.form.submit();" style="background:url(/images/bt_them.jpg); width:55px; height:65px;">
		</td>		
		<td style="border-top:1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-right:1px solid #CCCCCC; height:65px; width:55px">
		<input type="button" value='' onClick="document.form.action='/sitemanager/?m=khtt&b=khtt-xl-xoa';document.form.submit();" style="background:url(/images/bt_xoa.jpg); width:55px; height:65px;">       
        </td>
      </tr>
    </table>
    
<table width="735" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="6" class="tieude" align="center">DANH SÁCH SẢN PHẨM</td>
  </tr>
  <tr height="30" bgcolor="#FFCC99">
    <td align="center" width="50" style="border-left:1px solid #333;border-right:1px solid #333">Chọn</td>
    <td align="center" width="150" style="border-right:1px solid #333"><strong>Tên khách hàng</strong></td>
    <td align="center" width="150" style="border-right:1px solid #333"><strong>Loại hình kinh doanh</strong></td>
    <td align="center" width="285" style="border-right:1px solid #333"><strong>Địa chỉ</strong></td>    
    <td align="center" width="50" style="border-right:1px solid #333"><strong>Sửa</strong></td>
    <td align="center" width="50"><strong>Xóa</strong></td>    
  </tr>  
<?php
		$tp=$_GET["tp"];
		$q=$_GET["q"];
//		echo "$tp";
		if(isset($_REQUEST["tp"])){
	        $kq=mysql_query("select count(*) from khachhangthanthiet where thanhpho='$tp'"); }
		else{
			if(isset($_REQUEST["q"])){
		        $kq=mysql_query("select count(*) from khachhangthanthiet where quan='$q'"); }
			else{
	        	$kq=mysql_query("select count(*) from khachhangthanthiet"); }
		}
        $r=mysql_fetch_array($kq);
        $numrow=$r[0];		
        //số record cho 1 trang
        $pagesize=20;
        //Tính tổng số trang
        $pagecount=ceil($numrow/$pagesize);			
        //Xác định số trang cho mỗi lần hiển thị
        $segsize=5;
        //Thiết lập trang hiện hành
        if(!isset($_GET["page"]))
			 $curpage=1;
        else	
        	 $curpage=$_GET["page"];
        if($curpage<1)
			 $curpage=1;
        if($curpage>$pagecount) $curpage=$pagecount;
        //Xác định số phân đoạn của trang
        $numseg=($pagecount % $segsize==0)?($pagecount/$segsize):(int)($pagecount/$segsize+1);
        //Xác định phân đoạn hiện hành của trang
        $curseg=($curpage % $segsize==0)?($curpage/$segsize):(int)($curpage/$segsize+1);   
		$k=($curpage-1)*$pagesize;
		
	//******************************** Nội Dung *********************************//
		if(isset($_REQUEST["tp"])){
			$sql3="select * from khachhangthanthiet where thanhpho='$tp' order by quan limit $k,$pagesize";}
		else{	
			if(isset($_REQUEST["q"])){
		        $sql3="select * from khachhangthanthiet where quan='$q' limit $k,$pagesize"; }
			else{
			$sql3="select * from khachhangthanthiet order by quan limit $k,$pagesize";}
		}
//	echo "$sql3";
		$kq3=mysql_query($sql3);
		if(!$kq3)
			echo "";
		else{
		while($r3=mysql_fetch_array($kq3))
		{
			$idkh=$r3["id_khtt"];$thanhpho=$r3["thanhpho"];
			$ten=$r3['ten']; $loaihinhkd=$r3['loaihinhkd']; $diachi=$r3["diachi"];
  ?>
  <tr>
  <td width="50" align="center" style="border-left:1px solid #333;border-bottom:1px solid #333; border-right:1px solid #333">
  <input type="checkbox" name="chon[]" value="<?php echo $idkh; ?>"/></td>  
    <td width="150" align="center" style="border-bottom:1px solid #333; border-right:1px solid #333"><b><?php echo "$ten"; ?></b></td>
    <td width="150" align="center" style="border-bottom:1px solid #333; border-right:1px solid #333"><?php echo "$loaihinhkd"; ?></td>
    <td width="285" style="border-bottom:1px solid #333; border-right:1px solid #333">
<div style="padding-left:5px; padding-right:5px" align="justify"><?php echo "$diachi"; ?></div></td>
    <td width="50" align="center" style="border-bottom:1px solid #333; border-right:1px solid #333"><a href="">Sửa</a></td>
    <td width="50" align="center" style="border-bottom:1px solid #333; border-right:1px solid #333"><a href="?m=khtt&b=khtt-del&idkh=<?php echo "$idkh"; ?>" onclick="return checkkhtt()">Xóa</a>
    </td>
  </tr>
 <?php	 
		}
		}
 ?>
  <tr>
	<td colspan="6" class="ketthuc">
 <?php
 	$tp=$_GET["tp"];
    if($numrow==0)
		echo "Lỗi SQL!!";
	else{  
	if(isset($_REQUEST["tp"])){
    if($curseg>1)
        echo "<a href='?m=khtt&b=khtt-list&tp=$tp&page=".(($curseg-1)*$segsize)."'><b>Previous</b></a> &nbsp;";
        $n=$curseg*$segsize<=$pagecount?$curseg*$segsize:$pagecount;
        for($i=($curseg-1)*$segsize+1;$i<=$n;$i++)
		{
			if($curpage==$i)
				echo "<a href='?m=khtt&b=khtt-list&tp=$tp&page=".$i."'><font color='#FF0000'>[".$i."]</font></a> &nbsp;";
			else
				echo "<a href='?m=khtt&b=khtt-list&tp=$tp&page=".$i."'><font color='#FFF'>[".$i."]</font></a> &nbsp;";
		}
        if($curseg<$numseg)
		echo "<a href='?m=khtt&b=khtt-list&tp=$tp&page=".(($curseg*$segsize)+1)."'><b>Next</b></a> &nbsp;";			
	}
	else{
    if($curseg>1)
        echo "<a href='?m=khtt&b=khtt-list&page=".(($curseg-1)*$segsize)."'><b>Previous</b></a> &nbsp;";
        $n=$curseg*$segsize<=$pagecount?$curseg*$segsize:$pagecount;
        for($i=($curseg-1)*$segsize+1;$i<=$n;$i++)
		{
			if($curpage==$i)
				echo "<a href='?m=khtt&b=khtt-list&page=".$i."'><font color='#FF0000'>[".$i."]</font></a> &nbsp;";
			else
				echo "<a href='?m=khtt&b=khtt-list&page=".$i."'><font color='#FFF'>[".$i."]</font></a> &nbsp;";
		}
        if($curseg<$numseg)
		echo "<a href='?m=khtt&b=khtt-list&page=".(($curseg*$segsize)+1)."'><b>Next</b></a> &nbsp;";		
	}
	}
?>
    </td>
  </tr> 
</table>
</form>